﻿// 1.1.3.13. We are given integer number n, value v (v=0 or 1) and a position p. Write a sequence of
// operators that modifies n to hold the value v at the position p from the binary representation of n.

using System;

class ChangingAnyBitInNum
{
    static void Main()
    {
        while (true)
        {
            Console.Write("Please enter integer number: ");
            int number = int.Parse(Console.ReadLine());
            Console.WriteLine(Convert.ToString(number, 2).PadLeft(32, '0'));
            Console.Write("Please enter position of the bit you want to set its value: ");
            byte positionBit = byte.Parse(Console.ReadLine());
            Console.Write("Please enter the value of the bit you want to set: ");
            byte valueBit = byte.Parse(Console.ReadLine());
            if (valueBit == 1)
            {
                number = number | (1 << positionBit);
            }
            else
            {
                number = number & (~(1 << positionBit));
            }
            Console.WriteLine(Convert.ToString(number, 2).PadLeft(32, '0'));
            Console.WriteLine();
        }
    }
}